<?php
namespace Mob \ Model;

use Think \ Model;
use Think \ Hook;
/**分享模型
 * Class InfoModel
 */

require_once ('./Application/Mob/Common/function.php');

class ShareModel extends Model {
  protected $tableName = 'share_record';

  /* 创建分享记录 creatorShare
   * @param int $shareUid 分享人Uid
   * @param int $mode     分享模式1=微信分享好友,2=微信分享朋友圈
   * @param string $link  分享的链接地址
   * @param string $title 分享的标题
   * @param string $imgUrl 分享的图片url
   * @param string $businessID 分享的业务流水号
   * @param string $type  分享的类型 分享类型,music、video或link，不填默认为link
   * @param string $desc  分享描述
   * @return string serialno 如果创建成功，则直接返回分享流水号
   */
  public function creatorShare($shareUid,$mode,$link,$title,$imgUrl,$businessID,$businessType,$type='link',$desc=null)
  {
   $data['serialno']=getSerialno(19);
   $data['operateTime']=time();
   $data['shareUid']=$shareUid;
   $data['mode']=$mode;
   $data['link']=$link;
   $data['title']=$title;
   $data['imgUrl']=$imgUrl;
   $data['status']=0; //默认状态
   $data['desc']=$desc;
   $data['type']=$type;
   $data['businessID']=$businessID;
   $data['businessType']=$businessType;
   if($this->add($data))
   {
   return $data['serialno'];
   }
  }
  /* 更新分享状态 updateShareResult
   * @param string $serialno 分享流水号
   * @param int  $shareFlg 分享结果
   * @param string  $errcode 错误代码
   * @param string  $errmsg  错误原因
   * @return bool  true 更新状态
   */
  public function updateShareResult($serialno,$shareFlg,$errcode,$errmsg)
  {
   $this->where(array('serialno'=>$serialno,'status'=>0))->save(array('status'=>$shareFlg,'errcode'=>$errcode,'errmsg'=>$errmsg,'completeTime'=>time()));
   return true;
  }

  public function get_shareDetails($serialno)
  {
  return $this->where(array('serialno'=>$serialno))->field('serialno,operateTime,shareUid,mode,link,title,imgUrl,status,desc,type,resultFlg,businessID,businessType,errcode,errmsg,completeTime')->find();
  }









}